//마감적용
function magam_apply(gubun, apply){
	var pro_id=document.getElementById("pro_id").value;
	var flag=false;
	if(apply=="Y"){
		 //flag=confirm("마감 후 관리자 외 수정이 불가합니다.    마감하시겠습니까?");
		flag=confirm("마감하시겠습니까?");
	}else{
		flag=true;
	}
	if(flag){
		createXMLHttpRequest();
		xhr.onreadystatechange = magam_applyResult;
		xhr.open("POST","riskIAction.do",true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
		xhr.send("mode=magam_apply&gubun="+gubun+"&apply="+apply+"&pro_id="+pro_id);
	}else{
		return false;
	}
}

function magam_applyResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			//alert(jsonData.arrList.length);
				//alert(jsonData.list.state1+"/"+jsonData.list.state2+"/"+jsonData.list.state3+"/"+jsonData.list.state4+"/"+jsonData.list.state5+"/"+jsonData.list.state6+"/"+jsonData.list.state7);
			/*
			var pbid="pb"+jsonData.gubun;
			var classNameCur="procssApplyButton"+jsonData.gubun;
			var classNameNor="procssButton"+jsonData.gubun;
			
			
			
			if(jsonData.apply=='Y'){
				opener.document.getElementById(pbid).className = classNameCur;
			}else{
				opener.document.getElementById(pbid).className = classNameNor;
			}
			*/
			//그래프를 다시 뿌리기 위해 리로드(메인 화면일 경우)
			//alert(jsonData.graphList);
			//if(opener.document.getElementById("graphDiv")!=null){
			//opener.document.getElementById("graphDiv").innerHTML=jsonData.graphList;
			//opener.location.replace("projectAction.do?mode=projectApply&pro_id="+jsonData.pro_id+"&pro_nm="+jsonData.pro_nm+"&proDayIndex="+jsonData.proDayIndex);
			//return false;
			//}
			/*
				var pbid;
				var classNameCur;
				var classNameNor;
				if(jsonData.list.state1=='Y'){
					pbid="pb1";
					classNameCur="procssApplyButton1";
					opener.document.getElementById(pbid).className = classNameCur;
				}
				if(jsonData.list.state1=='N'){
						pbid="pb1";
						classNameNor="procssButton1";
						opener.document.getElementById(pbid).className = classNameNor;
				}				
				if(jsonData.list.state2=='Y'){
					pbid="pb2";
					classNameCur="procssApplyButton2";
					opener.document.getElementById(pbid).className = classNameCur;
				}
				if(jsonData.list.state2=='N'){
						pbid="pb2";
						classNameNor="procssButton2";
						opener.document.getElementById(pbid).className = classNameNor;
				}				
				if(jsonData.list.state3=='Y'){
					pbid="pb3";
					classNameCur="procssApplyButton3";
					opener.document.getElementById(pbid).className = classNameCur;
				}
				if(jsonData.list.state3=='N'){
						pbid="pb3";
						classNameNor="procssButton3";
						opener.document.getElementById(pbid).className = classNameNor;
				}
				if(jsonData.list.state4=='Y'){
					pbid="pb4";
					classNameCur="procssApplyButton4";
					opener.document.getElementById(pbid).className = classNameCur;
				}
				if(jsonData.list.state4=='N'){
						pbid="pb4";
						classNameNor="procssButton4";
						opener.document.getElementById(pbid).className = classNameNor;
				}
				if(jsonData.list.state5=='Y'){
					pbid="pb5";
					classNameCur="procssApplyButton5";
					opener.document.getElementById(pbid).className = classNameCur;
				}
				if(jsonData.list.state5=='N'){
						pbid="pb5";
						classNameNor="procssButton5";
						opener.document.getElementById(pbid).className = classNameNor;
				}
				if(jsonData.list.state6=='Y'){
						pbid="pb6";
						classNameCur="procssApplyButton6";
						opener.document.getElementById(pbid).className = classNameCur;
				}
				if(jsonData.list.state6=='N'){
						pbid="pb6";
						classNameNor="procssButton6";
						opener.document.getElementById(pbid).className = classNameNor;
				}
				if(jsonData.list.state7=='Y'){
						pbid="pb7";
						classNameCur="procssApplyButton7";
						opener.document.getElementById(pbid).className = classNameCur;
				}
				if(jsonData.list.state7=='N'){
						pbid="pb7";
						classNameNor="procssButton7";
						opener.document.getElementById(pbid).className = classNameNor;
				}
				*/
				opener.document.location.reload(); 
				window.close();
		}
	}
}



//marinfo_SI.jsp
//RA정보코드 유효성 검사
var rainfoIdFlag="Y";
function searchRainfoId(rainfoId,pro_id){
	rainfo_id=rainfoId.value;
	createXMLHttpRequest();
	xhr.onreadystatechange = searchRainfoIdResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
	xhr.send("mode=searchRainfoId&rainfo_id="+rainfo_id+"&pro_id="+pro_id);
}
function searchRainfoIdResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			 if(jsonData.rainfo_idFlag=="N"){
				 rainfoIdFlag="N";
			}else{
				rainfoIdFlag="Y";
			}
		}
	}
}

var xhr; // 비동기 서버 연동을 위한 객체
function createXMLHttpRequest(){
	if(window.ActiveXObject){//ms exploer 일 경우
		xhr=new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xhr=new XMLHttpRequest();	
	}
}

//mrainfo_SL(Rainfo_Id,Rainfo_Nm 값 세팅(컨테이너 tableList)
function setRaIdNm(rainfo_id,rainfo_nm, state){
	var pro_id=document.getElementById("conPro_id").value;
	createXMLHttpRequest();
	xhr.onreadystatechange = setRaIdNmResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
	xhr.send("mode=changeTracont1List&pro_id="+pro_id+"&rainfo_id="+rainfo_id+"&rainfo_nm="+rainfo_nm+"&state="+state);
	/*
	document.getElementById("rainfoID_div").style.display='';
	document.getElementById("racontListDiv").style.display='';
	document.getElementById("racontInsertDiv").style.display='';
	document.getElementById("rainfoID").innerHTML=rainfo_nm;
	document.getElementById("rainfo_id").value=rainfo_id;
	document.getElementById("rainfo_nm").value=rainfo_nm;
	*/
}
function setRaIdNmResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			document.getElementById("rainfoID_div").style.display='';
			//document.getElementById("racontListDiv").style.display='';
			//document.getElementById("racontInsertDiv").style.display='';
			document.getElementById("rainfoID").innerHTML=jsonData.rainfo_nm;
			document.getElementById("rainfo_id").value=jsonData.rainfo_id;
			//document.getElementById("rainfo_nm").value=jsonData.rainfo_nm;
			document.getElementById("racontListDivData").innerHTML=jsonData.contList1;
		}
	}
}

//onload 공통 컨테이너 리스트(mrainfo_SL.jsp)
function onloadTracont2List(state){
	//alert(pro_id);
	//alert(rainfo_id);
	createXMLHttpRequest();
	xhr.onreadystatechange = onloadTracont2ListResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
	xhr.send("mode=onloadTracont2List&state="+state);
}
function onloadTracont2ListResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			document.getElementById("racontPublicListDivData").innerHTML=jsonData.contList2;
		}
	}
}

//컨테이너 변경 (mrainfo_SL.jsp)
function changeCon(rainfo_id){
	var pro_id=document.getElementById("pro_id").value;
	//alert(pro_id);
	//alert(rainfo_id);
	createXMLHttpRequest();
	xhr.onreadystatechange = changeConResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
	xhr.send("mode=changeCon&pro_id="+pro_id+"&rainfo_id="+rainfo_id);
}
function changeConResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			 if(jsonData.flag=="N"){
				document.getElementById("changeConDiv").innerHTML="<table class='table-long'><tr class='odd'><td style='text-align: center; height: 35px ; vertical-align: middle;' colspan='5' valign='middle'>-컨테이너 값이 없습니다-</td></tr></table>";
			}else{
				document.getElementById("changeConDiv").innerHTML=jsonData.list;
			}
		}
	}
}

//컨테이너 등록
function tracont1_insertAjax(state){
	var form=document.tracontForm;
	var pro_id=document.getElementById("conPro_id").value;
	var rainfo_id=document.getElementById("rainfo_id");
	var base_lev1=form.base_lev1.value;
	var ak_nm2=form.ak_nm2;
	var racont_nm=form.racont_nm;
	var choice=form.choice;
	var choiceValue;
	//라디오버튼 벨류값 구해오기
	 for (var i=0;i<choice.length; i++ )
	  {
	    if (choice[i].checked)
	    {
	    	choiceValue=choice[i].value;
	    }
	  }
	if(Trim(rainfo_id.value)==""){
		alert("자산 목록을 선택후 이용가능합니다");
		return;
	}else if(Trim(ak_nm2.value)==""){
		alert("자산유형을 입력해주세요");
		ak_nm2.focus();
		return;
	}else if(Trim(racont_nm.value)==""){
		alert("컨테이너명을 입력해주세요");
		racont_nm.focus();
		return;
	}else	{
		var flag=confirm("등록하시겠습니까?");
		if(flag){
			createXMLHttpRequest();
			xhr.open("POST","riskIAction.do",true);
			xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
			if(choiceValue==1){
				xhr.onreadystatechange = tracont2_insertAjaxResult;
				xhr.send("mode=tracont2_insertAjax&pro_id="+pro_id+"&rainfo_id="+rainfo_id.value+"&base_lev1="+base_lev1+"&racont_nm="+racont_nm.value+"&state="+state);
			}else if(choiceValue==2){
				xhr.onreadystatechange = tracont1_insertAjaxResult;
				xhr.send("mode=tracont1_insertAjax&pro_id="+pro_id+"&rainfo_id="+rainfo_id.value+"&base_lev1="+base_lev1+"&racont_nm="+racont_nm.value+"&state="+state);
			}
		}else {
			return false;
		}
	}
}
function tracont1_insertAjaxResult(){
	var form=document.forms[1];
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			if(jsonData.useTracont2Flag=="Y"){
				//alert("등록실패 : 공통 컨테이너에 등록된 자산유형 및 컨테이너입니다");
				alert("등록실패 : 공통 컨테이너에 등록된 컨테이너입니다");
			}else{
				if(jsonData.insertFlag=="Y"){
					 var form1=document.tracontForm;
					 form1.ak_nm2.value="";
					 form1.base_lev1.value="";
					 form1.racont_nm.value="";
					document.getElementById("racontListDivData").innerHTML=jsonData.contList1;
				}else{
					alert("등록실패 : 동일한 컨테이너명이 있습니다");
					//document.getElementById("changeConDiv").innerHTML=jsonData.list;
				}
			}
		}
	}
}
function tracont2_insert(pro_id,rainfo_id,racont_nm, base_lev1,state){
	var flag=confirm("공통 컨테이너로 바꾸시겠습니까?");
	if(flag){
		createXMLHttpRequest();
		xhr.open("POST","riskIAction.do",true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
			xhr.onreadystatechange = tracont2_insertAjaxResult;
			xhr.send("mode=tracont2_insertAjax&pro_id="+pro_id+"&rainfo_id="+rainfo_id+"&base_lev1="+base_lev1+"&racont_nm="+racont_nm+"&state="+state);
	}else {
		return false;
	}
}
function tracont2_insertAjaxResult(){
	var form=document.forms[1];
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			 if(jsonData.insertFlag=="Y"){
				 var form1=document.tracontForm;
				 form1.ak_nm2.value="";
				 form1.base_lev1.value="";
				 form1.racont_nm.value="";
				document.getElementById("racontListDivData").innerHTML=jsonData.contList1;
				document.getElementById("racontPublicListDivData").innerHTML=jsonData.contList2;
			}else{
				alert("등록실패 : 동일한 컨테이너명이 있습니다");
				//document.getElementById("changeConDiv").innerHTML=jsonData.list;
			}
		}
	}
}
//컨테이너1 삭제
function tracont1_delete(pro_id, rainfo_id, racont_nm, state){
	var flag=confirm("삭제하시겠습니까?");
	if(flag){
		createXMLHttpRequest();
		xhr.open("POST","riskIAction.do",true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
			xhr.onreadystatechange = tracont1_deleteResult;
			xhr.send("mode=tracont1_delete&pro_id="+pro_id+"&rainfo_id="+rainfo_id+"&racont_nm="+racont_nm+"&state="+state);
	}else {
		return false;
	}
}
function tracont1_deleteResult(){
	var form=document.forms[1];
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
				 var form1=document.tracontForm;
				 //form1.ak_nm2.value="";
				 //form1.base_lev1.value="";
				 //form1.racont_nm.value="";
				document.getElementById("racontListDivData").innerHTML=jsonData.contList1;
		}
	}
}
//컨테이너2 삭제
function tracont2_delete(pro_id, racont_nm, state){
	var flag=confirm("삭제하시겠습니까?");
	if(flag){
		createXMLHttpRequest();
		xhr.open("POST","riskIAction.do",true);
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
			xhr.onreadystatechange = tracont2_deleteResult;
			xhr.send("mode=tracont2_delete&pro_id="+pro_id+"&racont_nm="+racont_nm+"&state="+state);
	}else {
		return false;
	}
}
function tracont2_deleteResult(){
	var form=document.forms[1];
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
				 //var form1=document.forms[1];
				 //form1.ak_nm2.value="";
				 //form1.base_lev1.value="";
				 //form1.racont_nm.value="";
				document.getElementById("racontPublicListDivData").innerHTML=jsonData.contList2;
		}
	}
}




//자산보안등급평가 등록
function mrainfo_insertAjax(){
	var form=document.forms[0];
	var pro_id=form.pro_id.value;
	var rainfo_id=form.rainfo_id;
	var rainfo_date=form.rainfo_date;
	var rainfo_nm=form.rainfo_nm;
	var rainfo_ver=form.rainfo_ver;
	var rainfo_writer=form.rainfo_writer;
	var rainfo_owner=form.rainfo_owner;
	var rainfo_doc=form.rainfo_doc;
	var rainfo_proc=form.rainfo_proc;
	var rainfo_site=form.rainfo_site;
	if(rainfo_id.value==""){
		alert("정보코드를 입력해주세요.");
		rainfo_id.focus();
		return;
	}else if(rainfo_date.value==""){
		alert("작성일자를 입력해주세요!!");
		rainfo_date.focus();
		return;
	}else if(Trim(rainfo_nm.value)==""){
		alert("정보명칭을 입력해주세요!!");
		rainfo_nm.focus();
		return;
	}else if(Trim(rainfo_ver.value)==""){
		alert("버전번호를 입력해주세요!!");
		rainfo_ver.focus();
		return;
	}else if(Trim(rainfo_writer.value)==""){
		alert("프로필 작성자를 입력해주세요!!");
		rainfo_writer.focus();
		return;
	}else if(Trim(rainfo_owner.value)==""){
		alert("정보소유자를 입력해주세요!!");
		rainfo_owner.focus();
		return;
	}else if(Trim(rainfo_proc.value)==""){
		alert("업무프로세스를 입력해주세요!!");
		rainfo_proc.focus();
		return;
	}else if(Trim(rainfo_site.value)==""){
		alert("지역/사이트를 입력해주세요!!");
		rainfo_site.focus();
		return;
	}else	{
		if(rainfoIdFlag=="N"){
			alert("동일한 자산 코드가 있습니다. 다른 값을 입력해주세요");
			return;
		}else{
			var flag=confirm("등록하시겠습니까?");
			if(flag){
				createXMLHttpRequest();
				xhr.onreadystatechange = mrainfoInsertAjaxResult;
				xhr.open("POST","riskIAction.do",true);
				xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
				xhr.send("mode=mrainfo_insertAjax&pro_id="+pro_id+"&rainfo_id="+rainfo_id.value+"&rainfo_date="+rainfo_date.value+"&rainfo_nm="+rainfo_nm.value+"&rainfo_ver="+rainfo_ver.value+"&rainfo_writer="+rainfo_writer.value+"&rainfo_owner="+rainfo_owner.value+"&rainfo_doc="+rainfo_doc.value+"&rainfo_proc="+rainfo_proc.value+"&rainfo_site="+rainfo_site.value);
			}else {
				return false;
			}
		}
	}
}
function mrainfoInsertAjaxResult(){
	var form=document.forms[0];
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			 if(jsonData.insertFlag=="Y"){
				 alert("등록성공");
				 form.rainfo_id.disabled = true;
				 document.getElementById("tracontInsertDiv").style.display='';
				 makeTracontTableAjax(jsonData.proId,jsonData.rainfoId);
			}else if(jsonData.updateFlag=="Y"){
				alert("수정성공");
			}else{
				alert("등록실패");
			}			 
		}
	}
}
//컨테이너 테이블 만들기
function makeTracontTableAjax(proId,rainfoId){
	//alert(proId+"|"+rainfoId);
	createXMLHttpRequest();
	xhr.onreadystatechange = makeTracontTableAjaxResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
	xhr.send("mode=makeTracontTableAjax&pro_id="+proId+"&rainfo_id="+rainfoId);
}
function makeTracontTableAjaxResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			 if(jsonData.flag=="N"){
				document.getElementById("tracontTable").innerHTML="<table class='table-short1' style='width: 300px; margin-left: 80px;'><tr class='odd'><td style='text-align: center; height: 35px ; vertical-align: middle;' colspan='4' valign='middle'>-컨테이너 값이 없습니다-</td></tr></table>";
			}else{
				document.getElementById("tracontTable").innerHTML=jsonData.list;
			}
		}
	}
}

//컨테이너 등록 테이블 생성
function tracontImfoDiv(ak_id,racont_id){
	var pro_id=document.getElementById("pro_id").value;
	var rainfo_id=document.getElementById("insertNum").value;
	document.getElementById("racont_nm").value="";
	createXMLHttpRequest();
	xhr.onreadystatechange = tracontImfoDivResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
	xhr.send("mode=tracontInsertTableAjax&pro_id="+pro_id+"&rainfo_id="+rainfo_id+"&ak_id="+ak_id+"&racont_id="+racont_id);
}
function tracontImfoDivResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			 if(jsonData.racont_nm==null){
				 document.getElementById("ak_id").value=jsonData.ak_id;
				 document.getElementById("ak_standard").value=jsonData.ak_standard;
				 document.getElementById("ak_type").value=jsonData.ak_type;
				 document.getElementById("racont_id").value=jsonData.racont_id;
			}else{
				 document.getElementById("ak_id").value=jsonData.ak_id;
				 document.getElementById("ak_standard").value=jsonData.ak_standard;
				 document.getElementById("ak_type").value=jsonData.ak_type;
				 document.getElementById("racont_id").value=jsonData.racont_id;
				 document.getElementById("racont_nm").value=jsonData.racont_nm;
			}
		}
	}
}
//컨테이너 등록
function tracont_insertAjax(){
	var form=document.forms[1];
	var pro_id=document.getElementById("pro_id").value;
	var rainfo_id=document.getElementById("insertNum").value;
	var racont_id=form.racont_id.value;
	var ak_id=form.ak_id.value;
	var racont_nm=form.racont_nm;
	var ak_type=form.ak_type;
	var ak_standard=form.ak_standard;
	if(Trim(ak_type.value)==""){
		alert("자산유형을 입력해주세요.");
		ak_type.focus();
		return;
	}else if(Trim(ak_standard.value)==""){
		alert("분류기준을 입력해주세요!!");
		ak_standard.focus();
		return;
	}else if(Trim(racont_nm.value)==""){
		alert("컨테이너명을 입력해주세요.");
		racont_nm.focus();
		return;
	}else	{
		var flag=confirm("등록하시겠습니까?");
		if(flag){
			createXMLHttpRequest();
			xhr.onreadystatechange = tracont_insertAjaxResult;
			xhr.open("POST","riskIAction.do",true);
			xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
			xhr.send("mode=tracont_insertAjax&pro_id="+pro_id+"&rainfo_id="+rainfo_id+"&racont_id="+racont_id+"&ak_id="+ak_id+"&racont_nm="+racont_nm.value);
		}else {
			return false;
		}
	}
}
function tracont_insertAjaxResult(){
	var form=document.forms[0];
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			 if(jsonData.insertFlag=="Y"){
				 alert("등록성공");
				 var form1=document.forms[1];
				 form1.racont_id.value="";
				 form1.ak_id.value="";
				 form1.ak_type.value="";
				 form1.ak_standard.value="";
				 form1.racont_nm.value="";
				 if(jsonData.flag=="N"){
						document.getElementById("tracontTable").innerHTML="<table class='table-short1' style='width: 300px; margin-left: 80px;'><tr class='odd'><td style='text-align: center; height: 35px ; vertical-align: middle;' colspan='4' valign='middle'>-컨테이너 값이 없습니다-</td></tr></table>";
					}else{
						document.getElementById("tracontTable").innerHTML=jsonData.list;
					}
			}else if(jsonData.updateFlag=="Y"){
				alert("수정성공");
				 if(jsonData.flag=="N"){
						document.getElementById("tracontTable").innerHTML="<table class='table-short1' style='width: 300px; margin-left: 80px;'><tr class='odd'><td style='text-align: center; height: 35px ; vertical-align: middle;' colspan='4' valign='middle'>-컨테이너 값이 없습니다-</td></tr></table>";
					}else{
						document.getElementById("tracontTable").innerHTML=jsonData.list;
					}
			}else{
				alert("등록실패");
				//document.getElementById("changeConDiv").innerHTML=jsonData.list;
			}
		}
	}
}

//평가표 자동 계산 스크립트
function mrainfopCiaSum(){
	var pro_id=document.getElementById("pro_id").value;
	var c_score=parseInt(document.getElementById("c_score").value);
	var i_score=parseInt(document.getElementById("i_score").value);
	var a_score=parseInt(document.getElementById("a_score").value);
	//var sum=parseFloat(a_c+a_i+a_a);
	var sum=c_score+i_score+a_score;
	//var jobScore=parseFloat(document.getElementById("job_score").value);
	//var assetScore=(jobScore*sum).toFixed(1);
	document.getElementById("t_score").value=sum;
	//document.getElementById("asset_score").value=assetScore;
	createXMLHttpRequest();
	xhr.onreadystatechange = mrainfopCiaSumResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8");
	//xhr.send("mode=ciaKind&assetScore="+assetScore);
	xhr.send("mode=autoAscuLevelSelect&sum="+sum+"&pro_id="+pro_id);
}
function mrainfopCiaSumResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			if(jsonData.ascu_id=="N"){
				document.getElementById("ascu_id").value="";
				document.getElementById("ascu_level").value="";
			}else{
				if(jsonData.ascu_level==undefined){
					document.getElementById("ascu_id").value="";
					document.getElementById("ascu_level").value="";
				}else{
					document.getElementById("ascu_id").value=jsonData.ascu_id;
					document.getElementById("ascu_level").value=jsonData.ascu_level;
				}
			}
		}
	}
}


//컨테이너에 매핑되어있는 ra정보테이블
function changeMappingTable(raitem_nm,gub){
	var pro_id=document.getElementById("pro_id").value;
	//alert(pro_id);
	//alert(rainfo_id);
	createXMLHttpRequest();
	xhr.onreadystatechange = changeMappingTableResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
	xhr.send("mode=changeMappingTable&pro_id="+pro_id+"&raitem_nm="+raitem_nm+"&gub="+gub);
}
function changeMappingTableResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
				document.getElementById("changeMappingTableDiv").innerHTML=jsonData.list;
				document.getElementById("totalMCount").innerHTML=jsonData.totalMCount;
		}
	}
}






//mvlist_SL(통제 명칭 보여주기)
function allTsNm(v_id){
	var pro_id=document.getElementById("pro_id").value;
	createXMLHttpRequest();
	xhr.onreadystatechange = allTsNmResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
	xhr.send("mode=allTsNm&pro_id="+pro_id+"&v_id="+v_id);
}
function allTsNmResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
				//document.getElementById("changeMappingTableDiv").innerHTML=jsonData.list;
				//document.getElementById("totalMCount").innerHTML=jsonData.totalMCount;
				document.getElementById("tsNmDiv1").style.display='';
				document.getElementById("tsNmDiv2").style.display='';
				document.getElementById("tsNmDiv3").style.display='';
				document.getElementById("tsNmDiv4").style.display='';
				document.getElementById("tsNm1").innerHTML=jsonData.ts_nm1;
				document.getElementById("tsNm2").innerHTML=jsonData.ts_nm2;
				document.getElementById("tsNm3").innerHTML=jsonData.ts_nm3;
				document.getElementById("tsNm4").innerHTML=jsonData.ts_nm4;
		}
	}
}



///
function ajaxTsCD(){
	var pro_id=document.getElementById("pro_id").value;
	var base_id="vl_level2";
	createXMLHttpRequest();
	xhr.onreadystatechange = ajaxTsCDResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
	var ty_cd=document.getElementById("ty_cd").value;
	xhr.send("mode=ajaxTsCD&pro_id="+pro_id+"&base_lev1="+ty_cd+"&base_id="+base_id);
}
function ajaxTsCDResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			alert(xhr.responseText);
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			alert(jsonData.vllist.length);
			//createOption(jsonData.subName);
		}
	}
}



///취약성 등급 (mrscore_SI.jsp)(onload)
function onloadVscore(vp_total){
	//alert(vp_total);
	if(vp_total=="0"){
		return; 
	}
	var pro_id=document.getElementById("pro_id").value;
	//alert(pro_id);
	createXMLHttpRequest();
	xhr.onreadystatechange = onloadVscoreResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
	xhr.send("mode=onloadVscore&pro_id="+pro_id+"&vp_total="+vp_total);
}
function onloadVscoreResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			//alert(xhr.responseText);
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			if(jsonData.v_level=="N"){
				//document.getElementById("vp_id").value="";
				for(var i = 0; i<document.getElementsByName("v_score").length;i++){
					document.getElementsByName("v_score").checked=0;
				 }
			}else{
				if(jsonData.v_level==undefined){
					//document.getElementById("vp_id").value="";
					for(var i = 0; i<document.getElementsByName("v_score").length;i++){
						document.getElementsByName("v_score").checked=0;
					 }
				}else{
					//document.getElementById("vp_id").value=jsonData.vp_id;
					
					for(var i = 0; i<document.getElementsByName("v_score").length;i++){
						if(document.getElementsByName("v_score")[i].value==jsonData.v_score){
							document.getElementsByName("v_score")[i].checked=1;
						}
					 }	
						
				}
			}
		}
	}
}



/*
 * //평가표 자동 계산 스크립트
function mrainfopCiaSum(){
	var pro_id=document.getElementById("pro_id").value;
	var c_score=parseInt(document.getElementById("c_score").value);
	var i_score=parseInt(document.getElementById("i_score").value);
	var a_score=parseInt(document.getElementById("a_score").value);
	//var sum=parseFloat(a_c+a_i+a_a);
	var sum=c_score+i_score+a_score;
	//var jobScore=parseFloat(document.getElementById("job_score").value);
	//var assetScore=(jobScore*sum).toFixed(1);
	document.getElementById("t_score").value=sum;
	//document.getElementById("asset_score").value=assetScore;
	createXMLHttpRequest();
	xhr.onreadystatechange = mrainfopCiaSumResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8");
	//xhr.send("mode=ciaKind&assetScore="+assetScore);
	xhr.send("mode=autoAscuLevelSelect&sum="+sum+"&pro_id="+pro_id);
}
function mrainfopCiaSumResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			if(jsonData.ascu_id=="N"){
				document.getElementById("ascu_id").value="";
				document.getElementById("ascu_level").value="";
			}else{
				if(jsonData.ascu_level==undefined){
					document.getElementById("ascu_id").value="";
					document.getElementById("ascu_level").value="";
				}else{
					document.getElementById("ascu_id").value=jsonData.ascu_id;
					document.getElementById("ascu_level").value=jsonData.ascu_level;
				}
			}
		}
	}
}
 */

/*
function createOption(obj){
	var sel=document.getElementById("second");
	delOption();
	for(i=0;i<obj.length;i++){
	//	alert(obj[i]);
		sel[i]=new Option(obj[i],obj[i]);
	}
}
function delOption(){
	var sel=document.getElementById("second");
	for(i=sel.options.length-1;i>=0;i--){
		sel.options[i]=null;
	}
}
*/

//자산위협매트릭스
function insertAtmetrix(obj,ak_id,base_lev1,base_lev2,base_lev3){
	var pro_id=document.getElementById("pro_id").value;
	var at_value=document.getElementById(obj).value;
	var flag;
	if(document.getElementById(obj).checked){
		
		//alert("체크 되있네");
		//flag=confirm("체크 하시겠습니까?");
		//if(flag){
			createXMLHttpRequest();
			xhr.onreadystatechange = insertAtmetrixResult;
			xhr.open("POST","riskIAction.do",true);
			xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
			xhr.send("mode=insertAtmetrix&pro_id="+pro_id+"&ak_id="+ak_id+"&base_lev1="+base_lev1+"&base_lev2="+base_lev2+"&base_lev3="+base_lev3+"&at_value="+at_value);
		//}else{
		//	document.getElementById(obj).checked=0;
		//}
	}else{
		//flag=confirm("체크해제 하시겠습니까?");
		//if(flag){
			createXMLHttpRequest();
			xhr.onreadystatechange = deleteAtmetrixResult;
			xhr.open("POST","riskIAction.do",true);
			xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
			xhr.send("mode=deleteAtmetrix&pro_id="+pro_id+"&ak_id="+ak_id+"&base_lev1="+base_lev1+"&base_lev2="+base_lev2+"&base_lev3="+base_lev3+"&at_value="+at_value);
		//}else{
		//	document.getElementById(obj).checked=1;
		//}
	}
	//alert(ak_id);
	//alert(base_lev1);	
	//alert(base_lev2);	
	//alert(base_lev3);	
}
function insertAtmetrixResult(){
if(xhr.readyState==4){
	if(xhr.status==200){
		var result=xhr.responseText;
		var jsonData=eval('('+result+')');
			if(jsonData.insertFlag=="Y"){
				//alert("입력 성공");
			}else{
				alert("입력 실패");
			}
		}
	}
}
function deleteAtmetrixResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
				if(jsonData.deleteFlag=="Y"){
					//alert("삭제 성공");
				}else{
					alert("삭제 실패");
				}
			}
		}
	}



//위험취약성매트릭스
function insertTvmetrix(obj,tk_id,ts_cd1,ts_cd2,ts_cd3,ts_cd4){
	var pro_id=document.getElementById("pro_id").value;
	var tv_value=document.getElementById(obj).value;
	var flag;
	if(document.getElementById(obj).checked){
		//flag=confirm("체크 하시겠습니까?");
		//if(flag){
			createXMLHttpRequest();
			xhr.onreadystatechange = insertTvmetrixResult;
			xhr.open("POST","riskIAction.do",true);
			xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
			xhr.send("mode=insertTvmetrix&pro_id="+pro_id+"&tk_id="+tk_id+"&ts_cd1="+ts_cd1+"&ts_cd2="+ts_cd2+"&ts_cd3="+ts_cd3+"&ts_cd4="+ts_cd4+"&tv_value="+tv_value);
		//}else{
		//	document.getElementById(obj).checked=0;
		//}
	}else{
		//flag=confirm("체크해제 하시겠습니까?");
		//if(flag){
			createXMLHttpRequest();
			xhr.onreadystatechange = deleteTvmetrixResult;
			xhr.open("POST","riskIAction.do",true);
			xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
			xhr.send("mode=deleteTvmetrix&pro_id="+pro_id+"&tk_id="+tk_id+"&ts_cd1="+ts_cd1+"&ts_cd2="+ts_cd2+"&ts_cd3="+ts_cd3+"&ts_cd4="+ts_cd4+"&tv_value="+tv_value);
		//}else{
		//	document.getElementById(obj).checked=1;
		//}
	}
	//alert(ak_id);
	//alert(base_lev1);	
	//alert(ts_cd3);	
	//alert(ts_cd4);	
}
function insertTvmetrixResult(){
if(xhr.readyState==4){
	if(xhr.status==200){
		var result=xhr.responseText;
		var jsonData=eval('('+result+')');
			if(jsonData.insertFlag=="Y"){
				//alert("입력 성공");
			}else{
				alert("입력 실패");
			}
		}
	}
}
function deleteTvmetrixResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
				if(jsonData.deleteFlag=="Y"){
					//alert("삭제 성공");
				}else{
					alert("삭제 실패");
				}
			}
		}
	}



//현황관리//stateReport_SP.jsp
//보안통제항목 콤보 박스 값 변경 ajax
function ts_nm3ListAjax(obj){
	var pro_id=document.getElementById("pro_id").value;
	var ts_nm2=obj.value;
	//alert(ts_nm2);
	createXMLHttpRequest();
	xhr.onreadystatechange = ts_nm3ListAjaxResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
	xhr.send("mode=ts_nm3ListAjax&ts_nm2="+ts_nm2+"&pro_id="+pro_id);
}
function ts_nm3ListAjaxResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			//alert(xhr.responseText);
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			//alert(jsonData.ts_nm3List);
			document.getElementById("ts_nm3Div").innerHTML=jsonData.ts_nm3List;
		}
	}
}






//컨테이너 클릭 이벤트
function  setContInfoAjax(racont_nm, base_lev1){
	var pro_id=document.getElementById("pro_id").value;
	createXMLHttpRequest();
	xhr.onreadystatechange = setContInfoAjaxResult;
	xhr.open("POST","riskIAction.do",true);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8");
	xhr.send("mode=setContInfoAjax&racont_nm="+racont_nm+"&base_lev1="+base_lev1+"&pro_id="+pro_id);
}
function  setContInfoAjaxResult(){
	if(xhr.readyState==4){
		if(xhr.status==200){
			var result=xhr.responseText;
			var jsonData=eval('('+result+')');
			document.getElementById("racont_nm").value=jsonData.racont_nm;
			var check1=document.getElementsByName("check1");
			var check2=document.getElementsByName("check2");
			for(var i = 0; i<check1.length;i++){
				//alert(check1[i].value);
				check1[i].checked = false ;
			}
			for(var i = 0; i<check2.length;i++){
				//alert(check1[i].value);
				check2[i].checked = false ;
			}
			
			
			
			if(jsonData.tracont2Flag=="Y"){
				for(var i = 0; i<check2.length;i++){
					//alert(check1[i].value);
					check2[i].checked = true ;
				}
			}else{
				var str =jsonData.list;
				for(j=0;j<str.length;j++){
					//alert(str[j]);
					for(var i = 0; i<check2.length;i++){
						//alert(check2[i].value);
						if(check2[i].value==str[j]){
						check2[i].checked = true ;
						}
					}
				}
			}
			//chkval = document.forms[1].check1.length;
			//var checkArray1 = document.forms[1].check1;
			//for(i=0;i<chkval;i++){
			//	alert(chekchArray1[i].value);
			//}
			//alert(jsonData.base_lev1);
			
			for(var i = 0; i<check1.length;i++){
					//alert(check1[i].value);
				if(check1[i].value==jsonData.base_lev1){
					check1[i].checked = true ;
				}
			}
			
		}
	}
}
